package com.movitech.mobile.cz.base.common.util;

import org.apache.commons.beanutils.BeanUtils;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * Created by Administrator on 2018/3/2.
 */
public class ListObjCopyUtil {
    /**
     * 复制集合
     * @param source
     * @param destinationClass
     * @param <E>
     * @return
     * @throws Exception
     */
    public static <E> List<E> copyTo(List<?> source, Class<E> destinationClass) throws Exception{
        if (source==null||source.size()==0) return Collections.emptyList();
        List<E> res = new ArrayList<E>(source.size());
        for (Object o : source) {
            E e = destinationClass.newInstance();
//            BeanUtils.copyProperties();
            org.springframework.beans.BeanUtils.copyProperties(o, e);
            res.add(e);
        }
        return res;
    }
}
